import Vue from "vue";
import VueRouter from "vue-router";
// import Home from "../views/Home.vue";
import store from "@/store";

Vue.use(VueRouter);

const routes = [
  {
    path: "/logon",
    name: "Logon",
    component: () => import("@/pages/Logon.vue"),
  },
  {
    path: "/content",
    name: "Content",
    component: () => import("@/pages/Content.vue"),
    children: [
      {
        path: "/home",
        name: "Home",
        component: () => import("@/views/Home.vue"),
      },
      {
        path: "/about",
        name: "About",
        component: () => import("@/views/About.vue"),
      },
      {
        path: "/player",
        name: "Player",
        component: () => import("@/views/Player.vue"),
      },
      {
        path: "/dealBill",
        name: "DealBill",
        component: () => import("@/views/DealBill.vue"),
      },
      {
        path: "/book",
        name: "Book",
        component: () => import("@/views/Book.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

const white = ["/logon", "/reg"];
router.beforeEach((to, from, next) => {
  if (!store.state.isAuth) {

    if (white.includes(to.path)) {
      // console.log("在白名单 ，不需要登录");
      next();
    } else {
      next("/logon");
    }
  } else {
    // console.log("bbbb");
    next();
  }
});

export default router;
